package com.oracle.oa.dao.impl;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;

import com.oracle.oa.dao.ScheduleDao;
import com.oracle.oa.entity.Schedule;

public class ScheduleDaoImpl extends BaseDaoImpl implements ScheduleDao {

	
	public List findByDCC(long DepartId, long cid, long createUser) {
		List list = null;
		
		String sql="from Schedule";
		
		if(DepartId!=0l&&cid!=0l&&createUser!=0l){
			sql="from Schedule s where s.departinfo.departid ="+DepartId+" and s.calendar.id="+cid+" and s.userinfo.userid ="+createUser;
		}else if(DepartId==0l&&cid!=0l&&createUser!=0l){
			sql="from Schedule s where s.calendar.id="+cid+" and s.userinfo.userid ="+createUser;
		}else if(DepartId!=0l&&cid==0L&&createUser!=0l){
			sql="from Schedule s where s.departinfo.departid ="+DepartId+" and s.userinfo.userid ="+createUser;
	    }else if(DepartId!=0l&&cid!=0L&&createUser==0l){
	    	sql="from Schedule s where s.departinfo.departid ="+DepartId+" and s.calendar.id="+cid;
	    }else if(DepartId==0l&&cid!=0L&&createUser==0l){
	    	sql="from Schedule s where s.calendar.id="+cid;
	    }else if(DepartId==0l&&cid==0L&&createUser!=0l){
	    	sql="from Schedule s where s.userinfo.userid ="+createUser;
	    }else if(DepartId!=0l&&cid==0L&&createUser==0l){
	    	sql="from Schedule s where s.departinfo.departid ="+DepartId;
	    }
		
	    try {
			list = this.getAllByHQL(sql);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return list;
	}

	/**
	 * 根据sql语句修改日历事件
	 */
	/*
	public boolean updateByHql(String hql) {
		boolean flag = false;
		// 打开session
		Session session = this.getHibernateTemplate().getSessionFactory()
				.openSession();
		// 执行sql语句
		try {
			int t = session.createQuery(hql).executeUpdate();
			if (t == 1) {
				flag = true;
			}
		} catch (HibernateException e) {
			e.printStackTrace();
		} finally {
			session.close();
		}
		return flag;
	}
*/
	/*
	public boolean add(Schedule schedule) {
		this.save(schedule);
		return true;
	}*/

	/*
	public boolean delete(Long scheduleid) {
		this.delete(new Schedule(scheduleid));
		return true;
	}
*/
	/*
	public boolean update(Schedule schedule) {
		this.update(schedule);
		return true;
	}*/


	/*
	public List<Schedule> find() {
		List<Schedule> list=null;
		list=(List<Schedule>)this.getAll(Schedule.class);
		return list;
	}*/

	/*
	public Schedule findById(Long scheduleid) {
		
		return (Schedule) this.getById(Schedule.class, scheduleid);
	}
*/
	

}
